Here is my opinion with no scriptures.
In bible times mental disorders such as schizophrenia and epilepsy were unheard of. Persons who displayed what we now know to be the recognisable symptoms of these disorders today, back then, had their illnesses attributed to demon possession.
I would ask, if the bible was written by an all seeing, knowing and loving god one would expect there to be clarification or instructions on mental illness. Even Christ did not correct such mistaken beliefs whilst on earth but perpetuated such misconceptions and myths by calling on demons to leave the afflicted person.
It is only as advancements in medicine have found ways to diagnose and treat psychological problems that the belief in demon possession has almost vanished in civilised western culture.
Belief in demon possession is still rife in parts of Africa where there is still ignorance of psychological disorders and those whose behaviour may be slightly different to the norm.